package com.gagakuai.bpm.dao.mapper.camunda;

import com.baomidou.mybatisplus.annotation.SqlParser;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;

import com.gagakuai.bpm.domian.dto.camunda.MyProcDto;
import com.gagakuai.bpm.domian.dto.camunda.TaskCommentDto;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface MyProcMapper extends BaseMapper<MyProcDto> {

    @SqlParser(filter = true)
    @Select(" SELECT p.BUSINESS_KEY_ id,  p.START_TIME_ startTime,  p.START_USER_ID_, u.FIRST_ userName " +
            " from ACT_HI_PROCINST p " +
            " left join ACT_ID_USER u on p.START_USER_ID_ = u.ID_ " +
            " ${ew.customSqlSegment} ")
    List<MyProcDto> listProcByPage(@Param(Constants.WRAPPER) QueryWrapper<MyProcDto> queryWrapper);

    @SqlParser(filter = true)
    @Select(" select proc.BUSINESS_KEY_ id,  proc.START_TIME_ startTime, task.DELETE_REASON_ state, " +
            " task.NAME_ taskName, task.ASSIGNEE_ handlerUserId, task.OWNER_ owner " +
            " from ACT_HI_TASKINST task " +
            " left join ACT_HI_PROCINST proc on proc.ID_ = task.PROC_INST_ID_  " +
            " ${ew.customSqlSegment} ")
    List<MyProcDto> listTaskByPage(@Param(Constants.WRAPPER) QueryWrapper<MyProcDto> queryWrapper);


    @Select("  select c.TIME_ time, c.USER_ID_ , " +
            "  u.FIRST_ userName, " +
            "  c.FULL_MSG_ fullMsg " +
            "  from ACT_HI_COMMENT c " +
            "  left join ACT_ID_USER u on u.ID_ = c.USER_ID_ " +
            "  where c.PROC_INST_ID_ = #{procId} " +
            "  order by c.TIME_  ")
    List<TaskCommentDto> listComment(@Param("procId")String procId);


    @Select(" select distinct p.BUSINESS_KEY_ businessKey from ACT_HI_PROCINST p " +
            " left join ACT_RU_TASK t on t.PROC_INST_ID_ = p.ID_ " +
            " where ASSIGNEE_ = #{userId} ")
    List<String> getMineRuningTask(@Param("userId")String userId);
}
